<template>
  <a-card>
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="myform" :model="model" :rules="validatorRules" style="width: 800px">
        <a-divider>欢迎语</a-divider>
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="男用户欢迎语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WelMaleMessage">
              <a-textarea v-model="model.WelMaleMessage" placeholder="请输入男用户欢迎语"></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="女用户欢迎语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="WelWomanMessage">
              <a-textarea v-model="model.WelWomanMessage" placeholder="请输入女用户欢迎语"  ></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-divider>提示语</a-divider>
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="视频通话提示语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="VideoMessage">
              <a-textarea v-model="model.VideoMessage" placeholder="请输入视频通话提示语"  ></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item v-bind="formItemLayoutWithOutLabel">
              <a-button type="primary" style="width: 150px;" @click="submitForm">确认修改</a-button>
            </a-form-model-item>

          </a-col>
        </a-row>

      </a-form-model>
    </a-spin>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'IntimacySetting',
  components: {},
  data () {
    return {
      model:{
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      formItemLayoutWithOutLabel: {
        wrapperCol: {
          xs: { span: 24, offset: 0 },
          sm: { span: 20, offset: 6 },
        },
      },
      confirmLoading: false,
      validatorRules: {
        WelMaleMessage: [
          { required: true, message: '请输入',name:'欢迎语-男用户欢迎语'},
        ],
        WelWomanMessage: [
          { required: true, message: '请输入',name:'欢迎语-女用户欢迎语'},
        ],
        VideoMessage: [
          { required: true, message: '请输入',name:'提示语-视频通话提示语'},
        ],
      },
    }
  },
  created() {
    this.getSystemConfigMap();
  },
  methods: {
    //获取回显数据
    getSystemConfigMap(){
      getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
        if(res.success){
          this.model=res.result;
        }
      })
    },
    //保存数据
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.myform.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '/system/systemConfig/saveOrUpdate';
          let method = 'post';
          let dataList=[];
          //格式化数据
          for(let key in this.model){
            let obj={};
            obj.code=key;
            obj.value=this.model[key];
            if(that.validatorRules[key]){
              obj.title=that.validatorRules[key][0].name;
              dataList.push(obj)
            }
          }
          httpAction(httpurl,dataList,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  },
}
</script>

<style scoped>

</style>